home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FDOPEN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  651 b   |  29 lines

  1. /* fdopen.c */
  2. #include <stdio.h>
  3. #include <io.h>
  4. #include <fcntl.h>
  5. main()
  6. {
  7.      int handle;
  8.      FILE *infile;
  9.      char buffer[80];
  10.             /* Open the file. Note that we need two '\' */
  11.     if ((handle = open("c:\\autoexec.bat", O_RDONLY)) == -1)
  12.     {
  13.         perror ("opened failed");
  14.         exit(1);
  15.     }
  16.         /* Use fdopen to assign a FILE data structure to file */
  17.     if ((infile = fdopen(handle, "r")) == NULL)
  18.     {
  19.         perror("fdopen failed");
  20.         exit(1);
  21.     }
  22.  
  23.         /* All's well. Read and print the contents of the file */
  24.      printf("Contents of c:\autoexec.bat:\n");
  25.      while (fgets(buffer, 80, infile) != NULL)
  26.      {
  27.         printf(buffer);
  28.      }
  29. }